﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Configuration;

namespace VK.Comm
{
    public static class ConfigManage
    {
        /// <summary>
        /// 设置 Web.config 中的键/值
        /// </summary>
        /// <param name="key">建</param>
        /// <param name="value">值</param>
        public static void SetAppSettings(string key, string value)
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");

            System.Configuration.KeyValueConfigurationCollection kvcc;
            kvcc = config.AppSettings.Settings;
            KeyValueConfigurationElement kvce = kvcc[key];
            if (kvce == null)
            {
                kvcc.Add(key, value);
            }
            else
            {
                kvce.Value = value;
            }
            config.Save();
        }
    }
}
